Acest dashboard este o replica inspirata de articolul lui Antoine Soetewey.
Ulterior, dashboardurile dezvoltate de Rami Krispin, cat si pachetele de date COVID-19 au reprezentat un punct de explorare al pachetului R ‘{flexdashboard}’.
Code
Codul este scris folosind R si frameworkul RMarkdown, disponibil pe github.
Data
Momentan folosesc datele disponibile in pachetul de dezvoltare, dar initial s-au folosit date de intrare din pachetul R {coronavirus}.
install.packages("devtools")
devtools::install_github("RamiKrispin/coronavirus")
Datele brute au sursa datele de la Johns Hopkins University Center for Systems Science and Engineering (JHU CCSE) Coronavirus. Acestea sunt actualizate zilnic, dar acest dashboard se actualizeaza la cateva zile, manual.
Ultimul update
Date disponibile din Wednesday August 26, 2020. Dashboardul a fost actualizat ultima oara:Thursday August 27, 2020.
Pentru alte proiecte de R, ma gasesti pe pagina mea personala.
---
title: covid-2020-Romania
output:
flexdashboard::flex_dashboard:
orientation: rows
source_code: embed
vertical_layout: fill
theme: bootstrap
---
```{r setup, include=FALSE}
#------------------ Packages ------------------
library(flexdashboard)
#install.packages("devtools")
#devtools::install_github("RamiKrispin/coronavirus", force = TRUE)
`%>%` <- magrittr::`%>%`
#------------------ Parameters ------------------
# Set colors
# https://www.w3.org/TR/css-color-3/#svg-color
confirmed_color <- "purple"
active_color <- "#1f77b4"
recovered_color <- "forestgreen"
death_color <- "red"
#------------------ Data ------------------
#data(coronavirus)
coronavirus <- read.csv("https://raw.githubusercontent.com/RamiKrispin/coronavirus/master/csv/coronavirus.csv", stringsAsFactors = FALSE)
coronavirus$date <- as.Date(coronavirus$date)
coronavirus <- coronavirus %>%
dplyr::filter(country == "Romania" |
country == "Greece" |
country == "Hungary" |
country == "Sweden")
#------------------ Data Preparation ------------------
df <- coronavirus %>%
dplyr::filter(country == "Romania") %>%
dplyr::group_by(country, type) %>%
dplyr::summarise(total = sum(cases)) %>%
tidyr::pivot_wider(
names_from = type,
values_from = total) %>%
dplyr::mutate(unrecovered = confirmed - ifelse(is.na(death), 0,death)-ifelse(is.na(recovered), 0, recovered)) %>%
dplyr::arrange(-confirmed) %>%
dplyr::ungroup()
df_daily <- coronavirus %>%
dplyr::filter(country == "Romania") %>%
dplyr::group_by(date, type) %>%
dplyr::summarise(total = sum(cases, na.rm = TRUE)) %>%
tidyr::pivot_wider(
names_from = type,
values_from = total
) %>%
dplyr::arrange(date) %>%
dplyr::ungroup() %>%
dplyr::mutate(active = confirmed - death) %>%
dplyr::mutate(
confirmed_cum = cumsum(confirmed),
death_cum = cumsum(death),
recovered_cum = cumsum(recovered),
active_cum = cumsum(active),
daily_confirmed_5D = round((confirmed +
dplyr::lag(confirmed, n = 1) +
dplyr::lag(confirmed, n = 2) +
dplyr::lag(confirmed, n = 3) +
dplyr::lag(confirmed, n = 4))/5,digits = 0),
daily_confirmed_7D = round((confirmed +
dplyr::lag(confirmed, n = 1) +
dplyr::lag(confirmed, n = 2) +
dplyr::lag(confirmed, n = 3) +
dplyr::lag(confirmed, n = 4) +
dplyr::lag(confirmed, n = 5) +
dplyr::lag(confirmed, n = 6))/7,digits = 0),
daily_confirmed_14D = round((confirmed +
dplyr::lag(confirmed, n = 1) +
dplyr::lag(confirmed, n = 2) +
dplyr::lag(confirmed, n = 3) +
dplyr::lag(confirmed, n = 4) +
dplyr::lag(confirmed, n = 5) +
dplyr::lag(confirmed, n = 6) +
dplyr::lag(confirmed, n = 7) +
dplyr::lag(confirmed, n = 8) +
dplyr::lag(confirmed, n = 9) +
dplyr::lag(confirmed, n = 10) +
dplyr::lag(confirmed, n = 11) +
dplyr::lag(confirmed, n = 12) +
dplyr::lag(confirmed, n = 13))/14,digits = 0)
) %>%
dplyr::mutate(
recover_rate = round((recovered /confirmed), digits = 4),
death_rate = round((death / confirmed),digits = 4)
)
df_daily <-df_daily %>% dplyr::arrange(desc(date))
df1 <- coronavirus %>% dplyr::filter(date == max(date))
```
Sumar
====
Row
-----------------------------------------------------------------------
### confirmed {.value-box}
```{r}
valueBox(
value = paste(format(sum(df$confirmed), big.mark = ","), "", sep = " "),
caption = "Total cazuri confirmate",
icon = "fas fa-user-md",
color = confirmed_color
)
```
### active {.value-box}
```{r}
valueBox(
value = paste(format(sum(df$unrecovered, na.rm = TRUE), big.mark = ","), " (",
round(100 * sum(df$unrecovered, na.rm = TRUE) / sum(df$confirmed), 1),
"%)",
sep = ""
),
caption = "Cazuri active (% of total cazuri)", icon = "fas fa-bed",
color = active_color
)
```
### death {.value-box}
```{r}
valueBox(
value = paste(format(sum(df$death, na.rm = TRUE), big.mark = ","), " (",
round(100 * sum(df$death, na.rm = TRUE) / sum(df$confirmed), 1),
"%)",
sep = ""
),
caption = "Cazuri deces (rata deces)",
icon = "fas fa-frown",
color = death_color
)
```
### recovered {.value-box}
```{r}
valueBox(
value = paste(format(sum(df$recovered, na.rm = TRUE), big.mark = ","), " (",
round(100 * sum(df$recovered, na.rm = TRUE) / sum(df$confirmed), 1),
"%)",
sep = ""
),
caption = "Cazuri vindecati (rata de vindecare)",
icon = "fas fa-user-check",
color = recovered_color
)
```
Column {.tabset}
-----------------------------------------------------------------------
### Evolutie cazuri noi
```{r}
plotly::plot_ly(data = df_daily,
x = ~ date,
y= ~ confirmed,
type = "scatter",
mode = "markers",
name = "Confirmati") %>%
plotly::add_lines(x = ~ date,
y = ~ daily_confirmed_14D,
line = list(color = "grey", width = 1),
name = "trend 14 zile") %>%
plotly::add_lines(x = ~ date,
y = ~ daily_confirmed_7D,
line = list(color = "maroon", width = 1),
name = "trend 7 zile") %>%
plotly::add_lines(x = ~ date,
y = ~ daily_confirmed_5D,
line = list(color = "red", width = 2),
name = "trend 5 zile") %>%
plotly::layout(title = "",
legend = list(x = 0.6, y = 0.9),
yaxis = list(title = "Number of Cases"),
xaxis = list(title = "Utilizarea mediei mobile pe 5, 7 and 14 zile pentru a evalua trendul"),
hovermode = "compare")
```
### Distributia cazurile totale
```{r}
plotly::plot_ly(data = df_daily,
x = ~ date,
y = ~ confirmed_cum,
name = 'Activi',
fillcolor = 'blue',
type = 'scatter',
mode = 'none',
stackgroup = 'one') %>%
plotly::add_trace( y = ~ death_cum,
name = "Decedati",
fillcolor = '#E41317') %>%
plotly::add_trace(y = ~recovered_cum,
name = 'Vindecati',
fillcolor = 'forestgreen') %>%
plotly::layout(title = "",
legend = list(x = 0.1, y = 0.9),
yaxis = list(title = "Cazuri confirmate"),
xaxis = list(title = "Sursa: COVID package, JHU CCSE"),
hovermode = "compared")
```
### Evolutia cumulativa a cazurilor confirmate
```{r}
plotly::plot_ly(data = df_daily) %>%
plotly::add_trace(
x = ~date,
y = ~confirmed_cum,
type = "scatter",
mode = "lines+markers",
name = "Confirmed",
line = list(color = active_color),
marker = list(color = active_color)
) %>%
plotly::add_trace(
x = ~date,
y = ~death_cum,
type = "scatter",
mode = "lines+markers",
name = "Death",
line = list(color = death_color),
marker = list(color = death_color)
) %>%
plotly::add_annotations(
x = as.Date("2020-02-04"),
y = 1,
text = paste("First case"),
xref = "x",
yref = "y",
arrowhead = 5,
arrowhead = 3,
arrowsize = 1,
showarrow = TRUE,
ax = -10,
ay = -90
) %>%
plotly::add_annotations(
x = as.Date("2020-03-22"),
y = 22,
text = paste("Primul deces"),
xref = "x",
yref = "y",
arrowhead = 5,
arrowhead = 3,
arrowsize = 1,
showarrow = TRUE,
ax = -10,
ay = -90
) %>%
plotly::add_annotations(
x = as.Date("2020-03-14"),
y = 22,
text = paste(
"Lockdown - Stare Urgenta"
),
xref = "x",
yref = "y",
arrowhead = 5,
arrowhead = 3,
arrowsize = 1,
showarrow = TRUE,
ax = -10,
ay = -120
) %>%
plotly::add_annotations(
x = as.Date("2020-05-15"),
y = 20,
text = paste(
"Stare de alerta"
),
xref = "x",
yref = "y",
arrowhead = 5,
arrowhead = 3,
arrowsize = 1,
showarrow = TRUE,
ax = -20,
ay = -120
) %>%
plotly::add_annotations(
x = as.Date("2020-08-02"),
y = 90,
text = paste(
"Masuri Noi"
),
xref = "x",
yref = "y",
arrowhead = 5,
arrowhead = 3,
arrowsize = 1,
showarrow = TRUE,
ax = -20,
ay = -150
) %>%
plotly::layout(
title = "",
yaxis = list(title = "Numar de cazuri cumulativ"),
xaxis = list(title = "Date"),
legend = list(x = 0.1, y = 0.9),
hovermode = "compare"
)
```
Sursa date
===
```{r}
df_daily %>%
DT::datatable(rownames = FALSE,
class = 'cell-border stripe',
colnames = c("Date", "Confirmed", "Recovered", "Death","Daily_confirmed_5D","Daily_confirmed_7D","Daily_confirmed_14D", "Recover Rate", "Death Rate"),
options = list(autowidth = TRUE,
dom = 'Blfrtip',
searchHighlight = TRUE,
pageLength = 14,
buttons = c('copy', 'csv')),
caption = htmltools::tags$caption(style = 'caption-side: bottom; text-align: center;','Sursa tabel: JHU CCSE.')) %>%
DT::formatPercentage("recover_rate", 2) %>%
DT::formatPercentage("death_rate", 2)
```
Comparatii
=======================================================================
Column {.tabset}
-------------------------------------
### **Cazuri confirmate zilnic - tari vecine sau cu risc**
```{r}
daily_confirmed <- coronavirus %>%
dplyr::filter(type == "confirmed") %>%
dplyr::filter(date >= "2020-02-29") %>%
dplyr::mutate(country = country) %>%
dplyr::group_by(date, country) %>%
dplyr::summarise(total = sum(cases)) %>%
dplyr::ungroup() %>%
tidyr::pivot_wider(names_from = country, values_from = total)
#----------------------------------------
# Plotting the data
daily_confirmed %>%
plotly::plot_ly() %>%
plotly::add_trace(
x = ~date,
y = ~Romania,
type = "scatter",
mode = "lines+markers",
name = "Romania"
) %>%
plotly::add_trace(
x = ~date,
y = ~Hungary,
type = "scatter",
mode = "lines+markers",
name = "Ungaria"
) %>%
plotly::add_trace(
x = ~date,
y = ~Greece,
type = "scatter",
mode = "lines+markers",
name = "Grecia"
) %>%
plotly::add_trace(
x = ~date,
y = ~Sweden,
type = "scatter",
mode = "lines+markers",
name = "Suedia"
) %>%
plotly::layout(
title = "",
legend = list(x = 0.1, y = 0.9),
yaxis = list(title = "Cazuri noi confirmate"),
xaxis = list(title = "Data"),
hovermode = "compare",
margin = list(
b = 10,
t = 10,
pad = 2
)
)
```
### **Distributia cazurilor dupa tipul lor**
```{r}
df_EU <- coronavirus %>%
dplyr::group_by(country, type) %>%
dplyr::summarise(total = sum(cases)) %>%
tidyr::pivot_wider(
names_from = type,
values_from = total
) %>%
dplyr::mutate(unrecovered = confirmed - ifelse(is.na(recovered), 0, recovered) - ifelse(is.na(death), 0, death)) %>%
dplyr::arrange(confirmed) %>%
dplyr::ungroup() %>%
dplyr::mutate(country = trimws(country)) %>%
dplyr::mutate(country = factor(country, levels = country))
plotly::plot_ly(
data = df_EU,
x = ~country,
y = ~ confirmed,
type = "bar",
name = "Confirmati",
marker = list(color = active_color)
) %>%
plotly::add_trace(
y = ~death,
name = "Decedati",
marker = list(color = death_color)
) %>%
plotly::layout(
barmode = "stack",
yaxis = list(title = "Total Cazuri"),
xaxis = list(title = ""),
hovermode = "compare",
margin = list(
b = 10,
t = 10,
pad = 2
)
)
```
Harta
=======================================================================
### ** Cazuri in lume** (*foloseste iconitele + sau - pentru zoom in/out | sectiune wip*)
```{r}
# map tab added by Art Steinmetz
library(leaflet)
library(leafpop)
library(purrr)
cv_data_for_plot <- coronavirus %>%
dplyr::filter(cases > 0) %>%
dplyr::group_by(country, province, lat, long, type) %>%
dplyr::summarise(cases = sum(cases)) %>%
dplyr::mutate(log_cases = 2 * log(cases)) %>%
dplyr::ungroup()
cv_data_for_plot.split <- cv_data_for_plot %>% split(cv_data_for_plot$type)
pal <- colorFactor(c("orange", "red", "green"), domain = c("confirmed", "death", "recovered"))
map_object <- leaflet() %>% addProviderTiles(providers$Stamen.Toner)
names(cv_data_for_plot.split) %>%
purrr::walk(function(df) {
map_object <<- map_object %>%
addCircleMarkers(
data = cv_data_for_plot.split[[df]],
lng = ~long, lat = ~lat,
color = ~ pal(type),
stroke = FALSE,
fillOpacity = 0.8,
radius = ~log_cases,
popup = leafpop::popupTable(cv_data_for_plot.split[[df]],
feature.id = FALSE,
row.numbers = FALSE,
zcol = c("type", "cases", "country", "province")
),
group = df,
labelOptions = labelOptions(
noHide = F,
direction = "auto"
)
)
})
map_object %>%
addLayersControl(
overlayGroups = names(cv_data_for_plot.split),
options = layersControlOptions(collapsed = FALSE)
)
```
Despre
=======================================================================
Acest dashboard este o replica inspirata de [articolul](https://www.statsandr.com/blog/how-to-create-a-simple-coronavirus-dashboard-specific-to-your-country-in-r/){target="_blank"} lui [Antoine Soetewey](https://www.antoinesoetewey.com).
Ulterior, dashboardurile dezvoltate de [Rami Krispin](https://ramikrispin.github.io/coronavirus_dashboard/){target="_blank"}, cat si pachetele de date COVID-19 au reprezentat un punct de explorare al pachetului R ['{flexdashboard}'](http://rmarkdown.rstudio.com/flexdashboard).
**Code**
Codul este scris folosind R si frameworkul RMarkdown, disponibil pe github.
**Data**
Momentan folosesc datele disponibile in pachetul de dezvoltare, dar initial s-au folosit date de intrare din pachetul R [`{coronavirus}`](https://github.com/RamiKrispin/coronavirus){target="_blank"}.
```
install.packages("devtools")
devtools::install_github("RamiKrispin/coronavirus")
```
Datele brute au sursa datele de la Johns Hopkins University Center for Systems Science and Engineering (JHU CCSE) Coronavirus.
Acestea sunt actualizate zilnic, dar acest dashboard se actualizeaza la cateva zile, manual.
**Ultimul update**
Date disponibile din `r format(max(coronavirus$date), "%A %B %d, %Y")`. Dashboardul a fost actualizat ultima oara:`r format(Sys.time(), "%A %B %d, %Y")`.
Pentru alte proiecte de R, ma gasesti pe [pagina mea personala](https://ineszz.rbind.io/).